<?php

// print_r($arrayName = array('a' => 1, ));

 //二分查找
  function bin_search($arr,$low,$high,$k)
  {
    if($low <= $high)
    {
      $mid = intval(($low + $high)/2);
      if($arr[$mid] == $k)
      {
        return $mid;
      }
      else if($k < $arr[$mid])
      {
        return bin_search($arr,$low,$mid-1,$k);
      }
      else
      {
        return bin_search($arr,$mid+1,$high,$k);
      }
    }
    return -1;
  }
 
  $arr = array(1,2,3,4,5,6,7,8,9,10);
 
  print_r(bin_search($arr,0,9,10));